<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of rememberMy
 *
 * @author ziad
 */
class rememberMe extends sfFilter {

    public function execute($filterChain) {
        if ($this->isFirstCall() ) {
            $user = $this->getContext()->getUser();
            $userIdSess = $user->getAttribute('userId');
            if($userIdSess == NULL){
                $userId = $this->getContext()->getRequest()->getCookie('userId');
                if ($userId) {
                    $exist = UsersLogin::checkIdExistance($userId);//check if exist
                    if($exist != false){
                        $user->setAuthenticated(true);
                        $user->setAttribute('userId', $userId);
                    }
                    else{
                        $this->getResponse()->setCookie('userId', $user['user_id'], time()-60*60*24*15);
                    }
                }
            }
        }
        $filterChain->execute();
    }

}

?>
